package com.hsj.busmanager.service;

import com.hsj.busmanager.api.Butie;
import com.hsj.busmanager.api.ButieType;
import com.hsj.busmanager.api.CostType;
import com.hsj.busmanager.mapper.ButieMapper;
import com.hsj.busmanager.mapper.ButieTypeMapper;
import com.hsj.busmanager.util.Page;
import com.hsj.busmanager.util.TabelData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ButieService {
    @Autowired
    private ButieTypeMapper butieTypeMapper;

    @Autowired
    private ButieMapper butieMapper;

    public TabelData<ButieType> getButieTypePage(Page page, ButieType butieType) {

        TabelData tabelData = new TabelData();

        Integer start = (page.getPage()-1)*page.getLimit();

        List<ButieType> butieTypeList = butieTypeMapper.getButieTypePage(start,page.getLimit(),butieType);

        int count = butieTypeMapper.getButieTypeCount(butieType);

        if (butieTypeList == null && butieTypeList.size() == 0) {
            return null;
        }

        tabelData.setCount(count);
        tabelData.setData(butieTypeList);

        return tabelData;


    }

    public ButieType getButieTypeByCostName(String butieName) {
        return butieTypeMapper.selectByPrimaryKey(butieName);
    }

    public void update(ButieType butieType) {
        butieTypeMapper.updateByPrimaryKeySelective(butieType);
    }

    public void deleteByButieName(String butieName) {
        butieTypeMapper.deleteByButieName(butieName);
    }

    public void insert(Butie butie) {
        butieMapper.insert(butie);
    }

    public void insert(ButieType butieType) {
        butieType.setUsed(1);
        butieTypeMapper.insert(butieType);
    }
}
